package cn.chongqing.han.toolkit.net;

import java.io.Serializable;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Created by Han Hui Long on 2017/12/7 10:32.
 */

public class RequestParam implements Serializable{
    private ConcurrentHashMap<String, String> urlParams;

    public RequestParam() {
        urlParams = new ConcurrentHashMap<>();
    }

    public RequestParam(Map<String, String> paramMap) {
        if (paramMap != null) {
            for (Map.Entry<String,String> entry:paramMap.entrySet()){
                urlParams.put(entry.getKey(),entry.getValue());
            }
        }
    }

    public void put(String key,String value){
        if (key != null && value != null){
            urlParams.put(key,value);
        }
    }

    @Override
    public String toString() {
        StringBuilder result = new StringBuilder();
        for (ConcurrentHashMap.Entry<String, String> entry : urlParams.entrySet()) {
            if (result.length() > 0)
                result.append("&");

            result.append(entry.getKey());
            result.append("=");
            result.append(entry.getValue());
        }


        return result.toString();
    }
}
